package com.itcodai.controller.course10;

import com.itcodai.entity.Role;
import com.itcodai.service.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author c-fanqj
 * @date 2023/3/27
 * @apiNote MyBatis Mapper接口使用
 */
@RestController
@RequestMapping("/role")
public class RoleMapperController {

    private static final Logger logger
            = LoggerFactory.getLogger(RoleMapperController.class);

    @Resource
    private RoleService roleService;

    @GetMapping("/getRole/{id}")
    public Role getUser(@PathVariable Long id) {
        return roleService.getRole(id);
    }

    @GetMapping("/getAndInsertRole")
    public Role getAndInsertRole(Role role) {
        logger.info("传入参数 role:{}", role);
        if (role.getId() == null) { // 插入
            return roleService.insertRole(role);
        }
        return roleService.getAndInsertRole(role);
    }



}
